﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BI.CF.PageList;
using BI.CF.Model;
using BI.CF.IDAL;
using System.Data.SqlClient;
using System.Data;
namespace BI.CF.DAL
{
    public class InvestGuanLi_DAL : InvestGuanLi_IDAL
    {
        /// <summary>
        /// 显示投标中的借款
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>
        public Pager<MemloanADNMinvest> Invest_Show_ing(int pagesize, int pageindex,int userid)
        {
            SqlParameter [] parameter ={
                                       new SqlParameter ("@UserID",SqlDbType.Int ){Value=userid},
                                       new SqlParameter("@PageIndex",SqlDbType.Int){Value=pageindex},
                                       new SqlParameter("@PageSize",SqlDbType.Int){Value=pagesize}
                                   };
            int totalcount=0;
            DataTable read = DbHelperSQL.RunProcedure("PROC_Indest_ing_JieKuan",parameter,pagesize,pageindex, out totalcount);
            List<MemloanADNMinvest> list = new List<MemloanADNMinvest>();
            for (int i = 0; i < read.Rows.Count; i++)
            {
                MemloanADNMinvest m = new MemloanADNMinvest();
                m.MemInvestId =Convert.ToInt32( read.Rows[i]["ID"]);
                m.BaiFenBi = read.Rows[i]["baifenbi"].ToString();
                m.LoanMoney = Convert.ToDecimal(read.Rows[i]["LoanMoney"]);
                m.Annualrate = Convert.ToDecimal(read.Rows[i]["Annualrate"].ToString());
                m.Title = read.Rows[i]["Title"].ToString();
                m.LaunchLoanTime = Convert.ToDateTime(read.Rows[i]["LaunchLoanTime"]);
                m.ExamineState = read.Rows[i]["ExamineState"].ToString();
                m.UserName = read.Rows[i]["UserName"].ToString();
                list.Add(m);
            };
            Pager<MemloanADNMinvest> pager = new Pager<MemloanADNMinvest>();
            pager.Data = list;
            if (totalcount%pagesize==0)
            {
                pager.PageCount = totalcount / pagesize;
            }
            else
            {
                pager.PageCount = totalcount / pagesize + 1;
            }
            pager.PageIndex = pageindex;
            pager.PageSize = pagesize;
            return pager;
        }

        /// <summary>
        /// 显示成功投标
        /// </summary>
        /// <param name="TouBiaoStarTime"></param>
        /// <param name="TouBiaoEndTimie"></param>
        /// <param name="UserID"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public Pager<MemloanADNMinvest> ChengGnong_Show(DateTime TouBiaoStarTime, DateTime TouBiaoEndTimie, int UserID, int PageIndex, int PageSize)
        {
            SqlParameter[] parameter ={
                                       new SqlParameter ("@TouBiaoStarTime",SqlDbType.VarChar ){Value=""},
                                       new SqlParameter("@TouBiaoEndTime",SqlDbType.VarChar){Value=""},
                                       new SqlParameter("@UserID",SqlDbType.Int){Value=UserID},
                                       new SqlParameter("@PageIndex",SqlDbType.Int){Value=PageIndex},
                                       new SqlParameter("@PageSize",SqlDbType.Int){Value=PageSize},
                                   };
            int totalcount = 0;
            DataTable read = DbHelperSQL.RunProcedure("PROC_Invest_ChengGong", parameter, PageSize, PageIndex, out totalcount);
            List<MemloanADNMinvest> list = new List<MemloanADNMinvest>();
            for (int i = 0; i < read.Rows.Count; i++)
            {
                MemloanADNMinvest m = new MemloanADNMinvest();
                m.MemInvestId = Convert.ToInt32(read.Rows[i]["ID"]);
                m.CollectIncome =Convert.ToDecimal( read.Rows[i]["CollectIncome"].ToString());
                m.LoanMoney = Convert.ToDecimal(read.Rows[i]["LoanMoney"]);
                m.Annualrate =Convert.ToDecimal(read.Rows[i]["ActualInvest"].ToString());
                m.Title = read.Rows[i]["Title"].ToString();
                m.LoanType = read.Rows[i]["LoanType"].ToString();
                m.LaunchLoanTime =Convert.ToDateTime( "2015-8-8".ToString());
                list.Add(m);
            };
            Pager<MemloanADNMinvest> pager = new Pager<MemloanADNMinvest>();
            pager.Data = list;
            if (totalcount % PageSize == 0)
            {
                pager.PageCount = totalcount / PageSize;
            }
            else
            {
                pager.PageCount = totalcount / PageSize + 1;
            }
            pager.PageIndex = PageIndex;
            pager.PageSize = PageSize;
            return pager;
        }

        /// <summary>
        /// 收款明细
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public Pager<ProfitModel> ShouYi_MingXi(int PageIndex, int PageSize, int UserID)
        {
            SqlParameter[] parameter ={
                                       new SqlParameter("@UserID",SqlDbType.Int){Value=UserID},
                                       new SqlParameter("@PageIndex",SqlDbType.Int){Value=PageIndex},
                                       new SqlParameter("@PageSize",SqlDbType.Int){Value=PageSize},
                                   };
            int totalcount = 0;
            DataTable read = DbHelperSQL.RunProcedure("PROC_Invest_ChengGong", parameter, PageSize, PageIndex, out totalcount);
            List<ProfitModel> list= new List<ProfitModel>();
            for (int i = 0; i < read.Rows.Count; i++)
            {
                ProfitModel m = new ProfitModel();
                m.ReceiptId = Convert.ToInt32(read.Rows[i]["ID"]);
                m.InvestMoney = Convert.ToDecimal(read.Rows[i]["InvestMoney"]);
                m.ReceiptMoney = Convert.ToDecimal(read.Rows[i]["ReceiptMoney"]);
                m.R_Money = Convert.ToDecimal(read.Rows[i]["R_Money"]);
                m.ReceiptTime = Convert.ToDateTime(read.Rows[i]["ReceiptTime"]);
                m.Title = read.Rows[i]["Title"].ToString();
                list.Add(m);
            };
            Pager<ProfitModel> pager = new Pager<ProfitModel>();
            pager.Data = list;
            if (totalcount % PageSize == 0)
            {
                pager.PageCount = totalcount / PageSize;
            }
            else
            {
                pager.PageCount = totalcount / PageSize + 1;
            }
            pager.PageIndex = PageIndex;
            pager.PageSize = PageSize;
            return pager;
        }
    }
}
